Reloadable dochandles - #385
Merged
Merged
Conversation
# Conflicts: # packages/providers/core/src/overlay-handle.ts # packages/providers/core/src/overlay-repo.ts
✅ Deploy Preview for gaiosub ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
🪡 PatchworkTorn down. |
paulsonnentag
marked this pull request as ready for review
July 27, 2026 13:02
chee
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Previously, when we resolved doc handles in a draft, we only did this once. Switching branches or scrubbing through history required remounting the editor every time to re-resolve the doc handle. This PR makes the resolution reactive, so you don’t lose UI state when switching branches, and scrubbing becomes much smoother.
Implementation
In
patchwork-systemwe wrap repo in a generic proxy that translates repo.find into "repo:handle-descriptor" request that other providers can respond to. A handle descriptor looks like this:By default, a document URL maps to itself, but providers can implement custom mappings. For example, a draft creates a clone of each document it contains; when a document is requested within the draft, the provider responds with the clone’s URL. The repo turns the returned doc handle descriptor into a doc handle that looks like the original (its url still reports the original), but reads and writes are delegated to the clone.
This PR makes the doc handle emit an artificial change event when it’s remapped to another doc, for example when the user switches drafts. To an editor, a branch switch looks like any other document change.
One exception: for editors that implement undo/redo, like tldraw and CodeMirror, the branch switch needs to reset the history stack. We solve this with the scopeReplaced flag introduced with sub doc handles: any artificial change event triggered by a remapping sets scopeReplaced = true.